package com.neusoft.zqygbc.neusoft_wenda.fragment;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.zqygbc.neusoft_wenda.R;
import com.neusoft.zqygbc.neusoft_wenda.adapter.CreateQuestionAdapter;
import com.neusoft.zqygbc.neusoft_wenda.adapter.QListAdapter;
import com.neusoft.zqygbc.neusoft_wenda.base.RetrofitCallback;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.MyQuestionList;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.QuestionEntity;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.QuestionList;
import com.neusoft.zqygbc.neusoft_wenda.model.QusetionModel;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

import static android.content.Context.MODE_PRIVATE;


/**
 * Created by dell on 2016/6/20.
 */
public class Fragment_1 extends Fragment {

    private RecyclerView recyerview;
    private LinearLayoutManager linearLayoutManager;
    private QusetionModel questionModel;
    private Call call;
    private RetrofitCallback<QuestionList> questionCallback;
    private QListAdapter adapter;
    private ArrayList<QuestionEntity> list = new ArrayList();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_1, null);

        initView(view);
        initData();
        return view;
    }

    private void initView(View view){

        recyerview = (RecyclerView) view.findViewById(R.id.recyerview_1);
        linearLayoutManager = new LinearLayoutManager(this.getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyerview.setLayoutManager(linearLayoutManager);
    }

    private void initData(){
        questionModel = new QusetionModel();
        call = questionModel.getQuestionByTid("1");
        questionCallback = new RetrofitCallback<QuestionList>() {
            @Override
            public void onResponse(QuestionList questionList) {
                list.addAll(questionList.getQuestion());
                adapter = new QListAdapter(getActivity(), list);
                recyerview.setAdapter(adapter);
            }
        };
        questionModel.bindCallback(call, questionCallback);
    }

}
